class Solution:
    def reverseVowels(self, s: str) -> str:
        s = list(s)
        temp = []
        for i in range(len(s)):
            if s[i] in "AEIOUaeiou":
                temp.append(s[i])
                s[i] = 1
        j = len(temp) - 1
        for i in range(len(s)):
            if s[i] == 1:
                s[i] = temp[j]
                j -= 1
        return (''.join(s))

# 方法二
class Solution:
    def reverseVowels(self, s: str) -> str:
        def isVowel(ch: str) -> bool:
            return ch in "AEIOUaeiou"
        
        n = len(s)
        s = list(s)

        i, j = 0, n - 1
        while i < j:
            while i < n and not isVowel(s[i]):
                i += 1
            while j > 0 and not isVowel(s[j]):
                j -= 1
            if i < j:
                s[i], s[j] = s[j], s[i]
                i += 1
                j -= 1

        return (''.join(s))